package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Ap0stoL2
 * Date: 2023-07-24
 * Time: 21:11
 */
//测试等待join
public class Demo10 {
    private static int i;

    public static void main(String[] args) {
        Thread b = new Thread(()->{

            for(int i=0;i<7;i++){
                System.out.println("i am thread B");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("b end ~");
        });

        Thread a = new Thread(()->{
            for(int i=0;i<3;i++){
                System.out.println("i am thread a");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            try {
                //到这里如果b还没执行完毕,则b.join就会让A线程在这个地方阻塞,从而等待b执行完毕
                b.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("a end ~");
        });

        b.start();
        a.start();

    }
}
